//
//  YSThemeManager.m
//  YaSha-iOS
//
//  Created by 方鹏俊 on 2017/7/27.
//

#import "YSThemeManager.h"

NSString *const YSThemeChangedNotification = @"YSThemeChangedNotification";
NSString *const YSThemeBeforeChangedName = @"YSThemeBeforeChangedName";
NSString *const YSThemeAfterChangedName = @"YSThemeAfterChangedName";

@implementation YSThemeManager

+ (instancetype)sharedInstance {
    static dispatch_once_t onceToken;
    static YSThemeManager *instance = nil;
    dispatch_once(&onceToken,^{
        instance = [[super allocWithZone:NULL] init];
    });
    return instance;
}

+ (id)allocWithZone:(struct _NSZone *)zone{
    return [self sharedInstance];
}

- (void)setCurrentTheme:(NSObject<YSThemeProtocol> *)currentTheme {
    BOOL isThemeChanged = _currentTheme != currentTheme;
    NSObject<YSThemeProtocol> *themeBeforeChanged = nil;
    if (isThemeChanged) {
        themeBeforeChanged = _currentTheme;
    }
    _currentTheme = currentTheme;
    if (isThemeChanged) {
        [currentTheme setupConfigurationTemplate];
        [[NSNotificationCenter defaultCenter] postNotificationName:YSThemeChangedNotification object:self userInfo:@{YSThemeBeforeChangedName: themeBeforeChanged ?: [NSNull null], YSThemeAfterChangedName: currentTheme ?: [NSNull null]}];
    }
}

@end
